package com.editor.smsmanager;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class ShareBgdView extends View {
    Paint mPaint;
    Paint mBgdPaint;

    int bgdColor = 0xff003300;
    float bgdPadding = 2;

    public ShareBgdView(Context context) {
        super(context);
        initPaint();
    }

    public ShareBgdView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    public ShareBgdView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        initPaint();
    }

    public void initPaint(){
        if(mPaint == null){
            mPaint = new Paint();
            mPaint.setColor(0xffffffff);
            mPaint.setStyle(Paint.Style.FILL);
        }

        if(mBgdPaint == null){
            mBgdPaint = new Paint();
            mBgdPaint.setColor(0xffffffff);
            mBgdPaint.setStyle(Paint.Style.FILL);
        }
    }

    public void setBgdColor(int bgdColor) {
        this.bgdColor = bgdColor;
        postInvalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawOval(0,0,getMeasuredWidth(),getMeasuredHeight(), mPaint);

        mBgdPaint.setColor(bgdColor);

        int padding = dip2px(bgdPadding);
        canvas.drawOval(padding,padding,getMeasuredWidth()-padding,getMeasuredHeight()-padding, mBgdPaint);
    }

    public int dip2px(float dpValue) {
        final float scale = getResources().getDisplayMetrics().density;
        return Math.round (dpValue * scale );
    }
}
